home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Programming / gcc-2.95.3-3 / info / gcc.info-9 < prev    next >
Encoding:
GNU Info File  |  2001-07-15  |  50.2 KB  |  1,231 lines

  1. This is Info file gcc.info, produced by Makeinfo version 1.68 from the
  2. input file ./gcc.texi.
  3.  
  4. INFO-DIR-SECTION Programming
  5. START-INFO-DIR-ENTRY
  6. * gcc: (gcc).                  The GNU Compiler Collection.
  7. END-INFO-DIR-ENTRY
  8.    This file documents the use and the internals of the GNU compiler.
  9.  
  10.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  11. Boston, MA 02111-1307 USA
  12.  
  13.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  14. 1999, 2000 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the sections entitled "GNU General Public License" and "Funding
  23. for Free Software" are included exactly as in the original, and
  24. provided that the entire resulting derived work is distributed under
  25. the terms of a permission notice identical to this one.
  26.  
  27.    Permission is granted to copy and distribute translations of this
  28. manual into another language, under the above conditions for modified
  29. versions, except that the sections entitled "GNU General Public
  30. License" and "Funding for Free Software", and this permission notice,
  31. may be included in translations approved by the Free Software Foundation
  32. instead of in the original English.
  33.  
  34. 
  35. File: gcc.info,  Node: Cross Runtime,  Next: Build Cross,  Prev: Cross Headers,  Up: Cross-Compiler
  36.  
  37. `libgcc.a' and Cross-Compilers
  38. ------------------------------
  39.  
  40.    Code compiled by GNU CC uses certain runtime support functions
  41. implicitly.  Some of these functions can be compiled successfully with
  42. GNU CC itself, but a few cannot be.  These problem functions are in the
  43. source file `libgcc1.c'; the library made from them is called
  44. `libgcc1.a'.
  45.  
  46.    When you build a native compiler, these functions are compiled with
  47. some other compiler-the one that you use for bootstrapping GNU CC.
  48. Presumably it knows how to open code these operations, or else knows how
  49. to call the run-time emulation facilities that the machine comes with.
  50. But this approach doesn't work for building a cross-compiler.  The
  51. compiler that you use for building knows about the host system, not the
  52. target system.
  53.  
  54.    So, when you build a cross-compiler you have to supply a suitable
  55. library `libgcc1.a' that does the job it is expected to do.
  56.  
  57.    To compile `libgcc1.c' with the cross-compiler itself does not work.
  58. The functions in this file are supposed to implement arithmetic
  59. operations that GNU CC does not know how to open code for your target
  60. machine.  If these functions are compiled with GNU CC itself, they will
  61. compile into infinite recursion.
  62.  
  63.    On any given target, most of these functions are not needed.  If GNU
  64. CC can open code an arithmetic operation, it will not call these
  65. functions to perform the operation.  It is possible that on your target
  66. machine, none of these functions is needed.  If so, you can supply an
  67. empty library as `libgcc1.a'.
  68.  
  69.    Many targets need library support only for multiplication and
  70. division.  If you are linking with a library that contains functions for
  71. multiplication and division, you can tell GNU CC to call them directly
  72. by defining the macros `MULSI3_LIBCALL', and the like.  These macros
  73. need to be defined in the target description macro file.  For some
  74. targets, they are defined already.  This may be sufficient to avoid the
  75. need for libgcc1.a; if so, you can supply an empty library.
  76.  
  77.    Some targets do not have floating point instructions; they need other
  78. functions in `libgcc1.a', which do floating arithmetic.  Recent
  79. versions of GNU CC have a file which emulates floating point.  With a
  80. certain amount of work, you should be able to construct a floating
  81. point emulator that can be used as `libgcc1.a'.  Perhaps future
  82. versions will contain code to do this automatically and conveniently.
  83. That depends on whether someone wants to implement it.
  84.  
  85.    Some embedded targets come with all the necessary `libgcc1.a'
  86. routines written in C or assembler.  These targets build `libgcc1.a'
  87. automatically and you do not need to do anything special for them.
  88. Other embedded targets do not need any `libgcc1.a' routines since all
  89. the necessary operations are supported by the hardware.
  90.  
  91.    If your target system has another C compiler, you can configure GNU
  92. CC as a native compiler on that machine, build just `libgcc1.a' with
  93. `make libgcc1.a' on that machine, and use the resulting file with the
  94. cross-compiler.  To do this, execute the following on the target
  95. machine:
  96.  
  97.      cd TARGET-BUILD-DIR
  98.      ./configure --host=sparc --target=sun3
  99.      make libgcc1.a
  100.  
  101. And then this on the host machine:
  102.  
  103.      ftp TARGET-MACHINE
  104.      binary
  105.      cd TARGET-BUILD-DIR
  106.      get libgcc1.a
  107.      quit
  108.  
  109.    Another way to provide the functions you need in `libgcc1.a' is to
  110. define the appropriate `perform_...' macros for those functions.  If
  111. these definitions do not use the C arithmetic operators that they are
  112. meant to implement, you should be able to compile them with the
  113. cross-compiler you are building.  (If these definitions already exist
  114. for your target file, then you are all set.)
  115.  
  116.    To build `libgcc1.a' using the perform macros, use
  117. `LIBGCC1=libgcc1.a OLDCC=./xgcc' when building the compiler.
  118. Otherwise, you should place your replacement library under the name
  119. `libgcc1.a' in the directory in which you will build the
  120. cross-compiler, before you run `make'.
  121.  
  122. 
  123. File: gcc.info,  Node: Cross Headers,  Next: Cross Runtime,  Prev: Tools and Libraries,  Up: Cross-Compiler
  124.  
  125. Cross-Compilers and Header Files
  126. --------------------------------
  127.  
  128.    If you are cross-compiling a standalone program or a program for an
  129. embedded system, then you may not need any header files except the few
  130. that are part of GNU CC (and those of your program).  However, if you
  131. intend to link your program with a standard C library such as `libc.a',
  132. then you probably need to compile with the header files that go with
  133. the library you use.
  134.  
  135.    The GNU C compiler does not come with these files, because (1) they
  136. are system-specific, and (2) they belong in a C library, not in a
  137. compiler.
  138.  
  139.    If the GNU C library supports your target machine, then you can get
  140. the header files from there (assuming you actually use the GNU library
  141. when you link your program).
  142.  
  143.    If your target machine comes with a C compiler, it probably comes
  144. with suitable header files also.  If you make these files accessible
  145. from the host machine, the cross-compiler can use them also.
  146.  
  147.    Otherwise, you're on your own in finding header files to use when
  148. cross-compiling.
  149.  
  150.    When you have found suitable header files, put them in the directory
  151. `/usr/local/TARGET/include', before building the cross compiler.  Then
  152. installation will run fixincludes properly and install the corrected
  153. versions of the header files where the compiler will use them.
  154.  
  155.    Provide the header files before you build the cross-compiler, because
  156. the build stage actually runs the cross-compiler to produce parts of
  157. `libgcc.a'.  (These are the parts that *can* be compiled with GNU CC.)
  158. Some of them need suitable header files.
  159.  
  160.    Here's an example showing how to copy the header files from a target
  161. machine.  On the target machine, do this:
  162.  
  163.      (cd /usr/include; tar cf - .) > tarfile
  164.  
  165.    Then, on the host machine, do this:
  166.  
  167.      ftp TARGET-MACHINE
  168.      lcd /usr/local/TARGET/include
  169.      get tarfile
  170.      quit
  171.      tar xf tarfile
  172.  
  173. 
  174. File: gcc.info,  Node: Build Cross,  Prev: Cross Runtime,  Up: Cross-Compiler
  175.  
  176. Actually Building the Cross-Compiler
  177. ------------------------------------
  178.  
  179.    Now you can proceed just as for compiling a single-machine compiler
  180. through the step of building stage 1.  If you have not provided some
  181. sort of `libgcc1.a', then compilation will give up at the point where
  182. it needs that file, printing a suitable error message.  If you do
  183. provide `libgcc1.a', then building the compiler will automatically
  184. compile and link a test program called `libgcc1-test'; if you get
  185. errors in the linking, it means that not all of the necessary routines
  186. in `libgcc1.a' are available.
  187.  
  188.    You must provide the header file `float.h'.  One way to do this is
  189. to compile `enquire' and run it on your target machine.  The job of
  190. `enquire' is to run on the target machine and figure out by experiment
  191. the nature of its floating point representation.  `enquire' records its
  192. findings in the header file `float.h'.  If you can't produce this file
  193. by running `enquire' on the target machine, then you will need to come
  194. up with a suitable `float.h' in some other way (or else, avoid using it
  195. in your programs).
  196.  
  197.    Do not try to build stage 2 for a cross-compiler.  It doesn't work to
  198. rebuild GNU CC as a cross-compiler using the cross-compiler, because
  199. that would produce a program that runs on the target machine, not on the
  200. host.  For example, if you compile a 386-to-68030 cross-compiler with
  201. itself, the result will not be right either for the 386 (because it was
  202. compiled into 68030 code) or for the 68030 (because it was configured
  203. for a 386 as the host).  If you want to compile GNU CC into 68030 code,
  204. whether you compile it on a 68030 or with a cross-compiler on a 386, you
  205. must specify a 68030 as the host when you configure it.
  206.  
  207.    To install the cross-compiler, use `make install', as usual.
  208.  
  209. 
  210. File: gcc.info,  Node: Sun Install,  Next: VMS Install,  Prev: Cross-Compiler,  Up: Installation
  211.  
  212. Installing GNU CC on the Sun
  213. ============================
  214.  
  215.    On Solaris, do not use the linker or other tools in `/usr/ucb' to
  216. build GNU CC.  Use `/usr/ccs/bin'.
  217.  
  218.    If the assembler reports `Error: misaligned data' when bootstrapping,
  219. you are probably using an obsolete version of the GNU assembler.
  220. Upgrade to the latest version of GNU `binutils', or use the Solaris
  221. assembler.
  222.  
  223.    Make sure the environment variable `FLOAT_OPTION' is not set when
  224. you compile `libgcc.a'.  If this option were set to `f68881' when
  225. `libgcc.a' is compiled, the resulting code would demand to be linked
  226. with a special startup file and would not link properly without special
  227. pains.
  228.  
  229.    There is a bug in `alloca' in certain versions of the Sun library.
  230. To avoid this bug, install the binaries of GNU CC that were compiled by
  231. GNU CC.  They use `alloca' as a built-in function and never the one in
  232. the library.
  233.  
  234.    Some versions of the Sun compiler crash when compiling GNU CC.  The
  235. problem is a segmentation fault in cpp.  This problem seems to be due to
  236. the bulk of data in the environment variables.  You may be able to avoid
  237. it by using the following command to compile GNU CC with Sun CC:
  238.  
  239.      make CC="TERMCAP=x OBJS=x LIBFUNCS=x STAGESTUFF=x cc"
  240.  
  241.    SunOS 4.1.3 and 4.1.3_U1 have bugs that can cause intermittent core
  242. dumps when compiling GNU CC.  A common symptom is an internal compiler
  243. error which does not recur if you run it again.  To fix the problem,
  244. install Sun recommended patch 100726 (for SunOS 4.1.3) or 101508 (for
  245. SunOS 4.1.3_U1), or upgrade to a later SunOS release.
  246.  
  247. 
  248. File: gcc.info,  Node: VMS Install,  Next: Collect2,  Prev: Sun Install,  Up: Installation
  249.  
  250. Installing GNU CC on VMS
  251. ========================
  252.  
  253.    The VMS version of GNU CC is distributed in a backup saveset
  254. containing both source code and precompiled binaries.
  255.  
  256.    To install the `gcc' command so you can use the compiler easily, in
  257. the same manner as you use the VMS C compiler, you must install the VMS
  258. CLD file for GNU CC as follows:
  259.  
  260.   1. Define the VMS logical names `GNU_CC' and `GNU_CC_INCLUDE' to
  261.      point to the directories where the GNU CC executables
  262.      (`gcc-cpp.exe', `gcc-cc1.exe', etc.) and the C include files are
  263.      kept respectively.  This should be done with the commands:
  264.  
  265.           $ assign /system /translation=concealed -
  266.             disk:[gcc.] gnu_cc
  267.           $ assign /system /translation=concealed -
  268.             disk:[gcc.include.] gnu_cc_include
  269.  
  270.      with the appropriate disk and directory names.  These commands can
  271.      be placed in your system startup file so they will be executed
  272.      whenever the machine is rebooted.  You may, if you choose, do this
  273.      via the `GCC_INSTALL.COM' script in the `[GCC]' directory.
  274.  
  275.   2. Install the `GCC' command with the command line:
  276.  
  277.           $ set command /table=sys$common:[syslib]dcltables -
  278.             /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
  279.           $ install replace sys$common:[syslib]dcltables
  280.  
  281.   3. To install the help file, do the following:
  282.  
  283.           $ library/help sys$library:helplib.hlb gcc.hlp
  284.  
  285.      Now you can invoke the compiler with a command like `gcc /verbose
  286.      file.c', which is equivalent to the command `gcc -v -c file.c' in
  287.      Unix.
  288.  
  289.    If you wish to use GNU C++ you must first install GNU CC, and then
  290. perform the following steps:
  291.  
  292.   1. Define the VMS logical name `GNU_GXX_INCLUDE' to point to the
  293.      directory where the preprocessor will search for the C++ header
  294.      files.  This can be done with the command:
  295.  
  296.           $ assign /system /translation=concealed -
  297.             disk:[gcc.gxx_include.] gnu_gxx_include
  298.  
  299.      with the appropriate disk and directory name.  If you are going to
  300.      be using a C++ runtime library, this is where its install
  301.      procedure will install its header files.
  302.  
  303.   2. Obtain the file `gcc-cc1plus.exe', and place this in the same
  304.      directory that `gcc-cc1.exe' is kept.
  305.  
  306.      The GNU C++ compiler can be invoked with a command like `gcc /plus
  307.      /verbose file.cc', which is equivalent to the command `g++ -v -c
  308.      file.cc' in Unix.
  309.  
  310.    We try to put corresponding binaries and sources on the VMS
  311. distribution tape.  But sometimes the binaries will be from an older
  312. version than the sources, because we don't always have time to update
  313. them.  (Use the `/version' option to determine the version number of
  314. the binaries and compare it with the source file `version.c' to tell
  315. whether this is so.)  In this case, you should use the binaries you get
  316. to recompile the sources.  If you must recompile, here is how:
  317.  
  318.   1. Execute the command procedure `vmsconfig.com' to set up the files
  319.      `tm.h', `config.h', `aux-output.c', and `md.', and to create files
  320.      `tconfig.h' and `hconfig.h'.  This procedure also creates several
  321.      linker option files used by `make-cc1.com' and a data file used by
  322.      `make-l2.com'.
  323.  
  324.           $ @vmsconfig.com
  325.  
  326.   2. Setup the logical names and command tables as defined above.  In
  327.      addition, define the VMS logical name `GNU_BISON' to point at the
  328.      to the directories where the Bison executable is kept.  This
  329.      should be done with the command:
  330.  
  331.           $ assign /system /translation=concealed -
  332.             disk:[bison.] gnu_bison
  333.  
  334.      You may, if you choose, use the `INSTALL_BISON.COM' script in the
  335.      `[BISON]' directory.
  336.  
  337.   3. Install the `BISON' command with the command line:
  338.  
  339.           $ set command /table=sys$common:[syslib]dcltables -
  340.             /output=sys$common:[syslib]dcltables -
  341.             gnu_bison:[000000]bison
  342.           $ install replace sys$common:[syslib]dcltables
  343.  
  344.   4. Type `@make-gcc' to recompile everything (alternatively, submit
  345.      the file `make-gcc.com' to a batch queue).  If you wish to build
  346.      the GNU C++ compiler as well as the GNU CC compiler, you must
  347.      first edit `make-gcc.com' and follow the instructions that appear
  348.      in the comments.
  349.  
  350.   5. In order to use GCC, you need a library of functions which GCC
  351.      compiled code will call to perform certain tasks, and these
  352.      functions are defined in the file `libgcc2.c'.  To compile this
  353.      you should use the command procedure `make-l2.com', which will
  354.      generate the library `libgcc2.olb'.  `libgcc2.olb' should be built
  355.      using the compiler built from the same distribution that
  356.      `libgcc2.c' came from, and `make-gcc.com' will automatically do
  357.      all of this for you.
  358.  
  359.      To install the library, use the following commands:
  360.  
  361.           $ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
  362.           $ library gnu_cc:[000000]gcclib/delete=L_*
  363.           $ library libgcc2/extract=*/output=libgcc2.obj
  364.           $ library gnu_cc:[000000]gcclib libgcc2.obj
  365.  
  366.      The first command simply removes old modules that will be replaced
  367.      with modules from `libgcc2' under different module names.  The
  368.      modules `new' and `eprintf' may not actually be present in your
  369.      `gcclib.olb'--if the VMS librarian complains about those modules
  370.      not being present, simply ignore the message and continue on with
  371.      the next command.  The second command removes the modules that
  372.      came from the previous version of the library `libgcc2.c'.
  373.  
  374.      Whenever you update the compiler on your system, you should also
  375.      update the library with the above procedure.
  376.  
  377.   6. You may wish to build GCC in such a way that no files are written
  378.      to the directory where the source files reside.  An example would
  379.      be the when the source files are on a read-only disk.  In these
  380.      cases, execute the following DCL commands (substituting your
  381.      actual path names):
  382.  
  383.           $ assign dua0:[gcc.build_dir.]/translation=concealed, -
  384.                    dua1:[gcc.source_dir.]/translation=concealed  gcc_build
  385.           $ set default gcc_build:[000000]
  386.  
  387.      where the directory `dua1:[gcc.source_dir]' contains the source
  388.      code, and the directory `dua0:[gcc.build_dir]' is meant to contain
  389.      all of the generated object files and executables.  Once you have
  390.      done this, you can proceed building GCC as described above.  (Keep
  391.      in mind that `gcc_build' is a rooted logical name, and thus the
  392.      device names in each element of the search list must be an actual
  393.      physical device name rather than another rooted logical name).
  394.  
  395.   7. *If you are building GNU CC with a previous version of GNU CC, you
  396.      also should check to see that you have the newest version of the
  397.      assembler*.  In particular, GNU CC version 2 treats global constant
  398.      variables slightly differently from GNU CC version 1, and GAS
  399.      version 1.38.1 does not have the patches required to work with GCC
  400.      version 2.  If you use GAS 1.38.1, then `extern const' variables
  401.      will not have the read-only bit set, and the linker will generate
  402.      warning messages about mismatched psect attributes for these
  403.      variables.  These warning messages are merely a nuisance, and can
  404.      safely be ignored.
  405.  
  406.      If you are compiling with a version of GNU CC older than 1.33,
  407.      specify `/DEFINE=("inline=")' as an option in all the
  408.      compilations.  This requires editing all the `gcc' commands in
  409.      `make-cc1.com'.  (The older versions had problems supporting
  410.      `inline'.)  Once you have a working 1.33 or newer GNU CC, you can
  411.      change this file back.
  412.  
  413.   8. If you want to build GNU CC with the VAX C compiler, you will need
  414.      to make minor changes in `make-cccp.com' and `make-cc1.com' to
  415.      choose alternate definitions of `CC', `CFLAGS', and `LIBS'.  See
  416.      comments in those files.  However, you must also have a working
  417.      version of the GNU assembler (GNU as, aka GAS) as it is used as
  418.      the back-end for GNU CC to produce binary object modules and is
  419.      not included in the GNU CC sources.  GAS is also needed to compile
  420.      `libgcc2' in order to build `gcclib' (see above); `make-l2.com'
  421.      expects to be able to find it operational in
  422.      `gnu_cc:[000000]gnu-as.exe'.
  423.  
  424.      To use GNU CC on VMS, you need the VMS driver programs `gcc.exe',
  425.      `gcc.com', and `gcc.cld'.  They are distributed with the VMS
  426.      binaries (`gcc-vms') rather than the GNU CC sources.  GAS is also
  427.      included in `gcc-vms', as is Bison.
  428.  
  429.      Once you have successfully built GNU CC with VAX C, you should use
  430.      the resulting compiler to rebuild itself.  Before doing this, be
  431.      sure to restore the `CC', `CFLAGS', and `LIBS' definitions in
  432.      `make-cccp.com' and `make-cc1.com'.  The second generation
  433.      compiler will be able to take advantage of many optimizations that
  434.      must be suppressed when building with other compilers.
  435.  
  436.    Under previous versions of GNU CC, the generated code would
  437. occasionally give strange results when linked with the sharable
  438. `VAXCRTL' library.  Now this should work.
  439.  
  440.    Even with this version, however, GNU CC itself should not be linked
  441. with the sharable `VAXCRTL'.  The version of `qsort' in `VAXCRTL' has a
  442. bug (known to be present in VMS versions V4.6 through V5.5) which
  443. causes the compiler to fail.
  444.  
  445.    The executables are generated by `make-cc1.com' and `make-cccp.com'
  446. use the object library version of `VAXCRTL' in order to make use of the
  447. `qsort' routine in `gcclib.olb'.  If you wish to link the compiler
  448. executables with the shareable image version of `VAXCRTL', you should
  449. edit the file `tm.h' (created by `vmsconfig.com') to define the macro
  450. `QSORT_WORKAROUND'.
  451.  
  452.    `QSORT_WORKAROUND' is always defined when GNU CC is compiled with
  453. VAX C, to avoid a problem in case `gcclib.olb' is not yet available.
  454.  
  455. 
  456. File: gcc.info,  Node: Collect2,  Next: Header Dirs,  Prev: VMS Install,  Up: Installation
  457.  
  458. `collect2'
  459. ==========
  460.  
  461.    GNU CC uses a utility called `collect2' on nearly all systems to
  462. arrange to call various initialization functions at start time.
  463.  
  464.    The program `collect2' works by linking the program once and looking
  465. through the linker output file for symbols with particular names
  466. indicating they are constructor functions.  If it finds any, it creates
  467. a new temporary `.c' file containing a table of them, compiles it, and
  468. links the program a second time including that file.
  469.  
  470.    The actual calls to the constructors are carried out by a subroutine
  471. called `__main', which is called (automatically) at the beginning of
  472. the body of `main' (provided `main' was compiled with GNU CC).  Calling
  473. `__main' is necessary, even when compiling C code, to allow linking C
  474. and C++ object code together.  (If you use `-nostdlib', you get an
  475. unresolved reference to `__main', since it's defined in the standard
  476. GCC library.  Include `-lgcc' at the end of your compiler command line
  477. to resolve this reference.)
  478.  
  479.    The program `collect2' is installed as `ld' in the directory where
  480. the passes of the compiler are installed.  When `collect2' needs to
  481. find the *real* `ld', it tries the following file names:
  482.  
  483.    * `real-ld' in the directories listed in the compiler's search
  484.      directories.
  485.  
  486.    * `real-ld' in the directories listed in the environment variable
  487.      `PATH'.
  488.  
  489.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  490.      if specified.
  491.  
  492.    * `ld' in the compiler's search directories, except that `collect2'
  493.      will not execute itself recursively.
  494.  
  495.    * `ld' in `PATH'.
  496.  
  497.    "The compiler's search directories" means all the directories where
  498. `gcc' searches for passes of the compiler.  This includes directories
  499. that you specify with `-B'.
  500.  
  501.    Cross-compilers search a little differently:
  502.  
  503.    * `real-ld' in the compiler's search directories.
  504.  
  505.    * `TARGET-real-ld' in `PATH'.
  506.  
  507.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  508.      if specified.
  509.  
  510.    * `ld' in the compiler's search directories.
  511.  
  512.    * `TARGET-ld' in `PATH'.
  513.  
  514.    `collect2' explicitly avoids running `ld' using the file name under
  515. which `collect2' itself was invoked.  In fact, it remembers up a list
  516. of such names--in case one copy of `collect2' finds another copy (or
  517. version) of `collect2' installed as `ld' in a second place in the
  518. search path.
  519.  
  520.    `collect2' searches for the utilities `nm' and `strip' using the
  521. same algorithm as above for `ld'.
  522.  
  523. 
  524. File: gcc.info,  Node: Header Dirs,  Prev: Collect2,  Up: Installation
  525.  
  526. Standard Header File Directories
  527. ================================
  528.  
  529.    `GCC_INCLUDE_DIR' means the same thing for native and cross.  It is
  530. where GNU CC stores its private include files, and also where GNU CC
  531. stores the fixed include files.  A cross compiled GNU CC runs
  532. `fixincludes' on the header files in `$(tooldir)/include'.  (If the
  533. cross compilation header files need to be fixed, they must be installed
  534. before GNU CC is built.  If the cross compilation header files are
  535. already suitable for ANSI C and GNU CC, nothing special need be done).
  536.  
  537.    `GPLUSPLUS_INCLUDE_DIR' means the same thing for native and cross.
  538. It is where `g++' looks first for header files.  The C++ library
  539. installs only target independent header files in that directory.
  540.  
  541.    `LOCAL_INCLUDE_DIR' is used only for a native compiler.  It is
  542. normally `/usr/local/include'.  GNU CC searches this directory so that
  543. users can install header files in `/usr/local/include'.
  544.  
  545.    `CROSS_INCLUDE_DIR' is used only for a cross compiler.  GNU CC
  546. doesn't install anything there.
  547.  
  548.    `TOOL_INCLUDE_DIR' is used for both native and cross compilers.  It
  549. is the place for other packages to install header files that GNU CC will
  550. use.  For a cross-compiler, this is the equivalent of `/usr/include'.
  551. When you build a cross-compiler, `fixincludes' processes any header
  552. files in this directory.
  553.  
  554. 
  555. File: gcc.info,  Node: C Extensions,  Next: C++ Extensions,  Prev: Installation,  Up: Top
  556.  
  557. Extensions to the C Language Family
  558. ***********************************
  559.  
  560.    GNU C provides several language features not found in ANSI standard
  561. C.  (The `-pedantic' option directs GNU CC to print a warning message if
  562. any of these features is used.)  To test for the availability of these
  563. features in conditional compilation, check for a predefined macro
  564. `__GNUC__', which is always defined under GNU CC.
  565.  
  566.    These extensions are available in C and Objective C.  Most of them
  567. are also available in C++.  *Note Extensions to the C++ Language: C++
  568. Extensions, for extensions that apply *only* to C++.
  569.  
  570. * Menu:
  571.  
  572. * Statement Exprs::     Putting statements and declarations inside expressions.
  573. * Local Labels::        Labels local to a statement-expression.
  574. * Labels as Values::    Getting pointers to labels, and computed gotos.
  575. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  576. * Constructing Calls::    Dispatching a call to another function.
  577. * Naming Types::        Giving a name to the type of some expression.
  578. * Typeof::              `typeof': referring to the type of an expression.
  579. * Lvalues::             Using `?:', `,' and casts in lvalues.
  580. * Conditionals::        Omitting the middle operand of a `?:' expression.
  581. * Long Long::        Double-word integers--`long long int'.
  582. * Complex::             Data types for complex numbers.
  583. * Hex Floats::          Hexadecimal floating-point constants.
  584. * Zero Length::         Zero-length arrays.
  585. * Variable Length::     Arrays whose length is computed at run time.
  586. * Macro Varargs::    Macros with variable number of arguments.
  587. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  588. * Pointer Arith::       Arithmetic on `void'-pointers and function pointers.
  589. * Initializers::        Non-constant initializers.
  590. * Constructors::        Constructor expressions give structures, unions
  591.                          or arrays as values.
  592. * Labeled Elements::    Labeling elements of initializers.
  593. * Cast to Union::       Casting to union type from any member of the union.
  594. * Case Ranges::        `case 1 ... 9' and such.
  595. * Function Attributes:: Declaring that functions have no side effects,
  596.                          or that they can never return.
  597. * Function Prototypes:: Prototype declarations and old-style definitions.
  598. * C++ Comments::        C++ comments are recognized.
  599. * Dollar Signs::        Dollar sign is allowed in identifiers.
  600. * Character Escapes::   `\e' stands for the character <ESC>.
  601. * Variable Attributes::    Specifying attributes of variables.
  602. * Type Attributes::    Specifying attributes of types.
  603. * Alignment::           Inquiring about the alignment of a type or variable.
  604. * Inline::              Defining inline functions (as fast as macros).
  605. * Extended Asm::        Assembler instructions with C expressions as operands.
  606.                          (With them you can define "built-in" functions.)
  607. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  608. * Explicit Reg Vars::   Defining variables residing in specified registers.
  609. * Alternate Keywords::  `__const__', `__asm__', etc., for header files.
  610. * Incomplete Enums::    `enum foo;', with details to follow.
  611. * Function Names::    Printable strings which are the name of the current
  612.              function.
  613. * Return Address::      Getting the return or frame address of a function.
  614. * Other Builtins::      Other built-in functions.
  615. * Deprecated Features:: Things might disappear from g++.
  616.  
  617. 
  618. File: gcc.info,  Node: Statement Exprs,  Next: Local Labels,  Up: C Extensions
  619.  
  620. Statements and Declarations in Expressions
  621. ==========================================
  622.  
  623.    A compound statement enclosed in parentheses may appear as an
  624. expression in GNU C.  This allows you to use loops, switches, and local
  625. variables within an expression.
  626.  
  627.    Recall that a compound statement is a sequence of statements
  628. surrounded by braces; in this construct, parentheses go around the
  629. braces.  For example:
  630.  
  631.      ({ int y = foo (); int z;
  632.         if (y > 0) z = y;
  633.         else z = - y;
  634.         z; })
  635.  
  636. is a valid (though slightly more complex than necessary) expression for
  637. the absolute value of `foo ()'.
  638.  
  639.    The last thing in the compound statement should be an expression
  640. followed by a semicolon; the value of this subexpression serves as the
  641. value of the entire construct.  (If you use some other kind of statement
  642. last within the braces, the construct has type `void', and thus
  643. effectively no value.)
  644.  
  645.    This feature is especially useful in making macro definitions "safe"
  646. (so that they evaluate each operand exactly once).  For example, the
  647. "maximum" function is commonly defined as a macro in standard C as
  648. follows:
  649.  
  650.      #define max(a,b) ((a) > (b) ? (a) : (b))
  651.  
  652. But this definition computes either A or B twice, with bad results if
  653. the operand has side effects.  In GNU C, if you know the type of the
  654. operands (here let's assume `int'), you can define the macro safely as
  655. follows:
  656.  
  657.      #define maxint(a,b) \
  658.        ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
  659.  
  660.    Embedded statements are not allowed in constant expressions, such as
  661. the value of an enumeration constant, the width of a bit field, or the
  662. initial value of a static variable.
  663.  
  664.    If you don't know the type of the operand, you can still do this,
  665. but you must use `typeof' (*note Typeof::.) or type naming (*note
  666. Naming Types::.).
  667.  
  668. 
  669. File: gcc.info,  Node: Local Labels,  Next: Labels as Values,  Prev: Statement Exprs,  Up: C Extensions
  670.  
  671. Locally Declared Labels
  672. =======================
  673.  
  674.    Each statement expression is a scope in which "local labels" can be
  675. declared.  A local label is simply an identifier; you can jump to it
  676. with an ordinary `goto' statement, but only from within the statement
  677. expression it belongs to.
  678.  
  679.    A local label declaration looks like this:
  680.  
  681.      __label__ LABEL;
  682.  
  683. or
  684.  
  685.      __label__ LABEL1, LABEL2, ...;
  686.  
  687.    Local label declarations must come at the beginning of the statement
  688. expression, right after the `({', before any ordinary declarations.
  689.  
  690.    The label declaration defines the label *name*, but does not define
  691. the label itself.  You must do this in the usual way, with `LABEL:',
  692. within the statements of the statement expression.
  693.  
  694.    The local label feature is useful because statement expressions are
  695. often used in macros.  If the macro contains nested loops, a `goto' can
  696. be useful for breaking out of them.  However, an ordinary label whose
  697. scope is the whole function cannot be used: if the macro can be
  698. expanded several times in one function, the label will be multiply
  699. defined in that function.  A local label avoids this problem.  For
  700. example:
  701.  
  702.      #define SEARCH(array, target)                     \
  703.      ({                                               \
  704.        __label__ found;                                \
  705.        typeof (target) _SEARCH_target = (target);      \
  706.        typeof (*(array)) *_SEARCH_array = (array);     \
  707.        int i, j;                                       \
  708.        int value;                                      \
  709.        for (i = 0; i < max; i++)                       \
  710.          for (j = 0; j < max; j++)                     \
  711.            if (_SEARCH_array[i][j] == _SEARCH_target)  \
  712.              { value = i; goto found; }              \
  713.        value = -1;                                     \
  714.       found:                                           \
  715.        value;                                          \
  716.      })
  717.  
  718. 
  719. File: gcc.info,  Node: Labels as Values,  Next: Nested Functions,  Prev: Local Labels,  Up: C Extensions
  720.  
  721. Labels as Values
  722. ================
  723.  
  724.    You can get the address of a label defined in the current function
  725. (or a containing function) with the unary operator `&&'.  The value has
  726. type `void *'.  This value is a constant and can be used wherever a
  727. constant of that type is valid.  For example:
  728.  
  729.      void *ptr;
  730.      ...
  731.      ptr = &&foo;
  732.  
  733.    To use these values, you need to be able to jump to one.  This is
  734. done with the computed goto statement(1), `goto *EXP;'.  For example,
  735.  
  736.      goto *ptr;
  737.  
  738. Any expression of type `void *' is allowed.
  739.  
  740.    One way of using these constants is in initializing a static array
  741. that will serve as a jump table:
  742.  
  743.      static void *array[] = { &&foo, &&bar, &&hack };
  744.  
  745.    Then you can select a label with indexing, like this:
  746.  
  747.      goto *array[i];
  748.  
  749. Note that this does not check whether the subscript is in bounds--array
  750. indexing in C never does that.
  751.  
  752.    Such an array of label values serves a purpose much like that of the
  753. `switch' statement.  The `switch' statement is cleaner, so use that
  754. rather than an array unless the problem does not fit a `switch'
  755. statement very well.
  756.  
  757.    Another use of label values is in an interpreter for threaded code.
  758. The labels within the interpreter function can be stored in the
  759. threaded code for super-fast dispatching.
  760.  
  761.    You can use this mechanism to jump to code in a different function.
  762. If you do that, totally unpredictable things will happen.  The best way
  763. to avoid this is to store the label address only in automatic variables
  764. and never pass it as an argument.
  765.  
  766.    ---------- Footnotes ----------
  767.  
  768.    (1) The analogous feature in Fortran is called an assigned goto, but
  769. that name seems inappropriate in C, where one can do more than simply
  770. store label addresses in label variables.
  771.  
  772. 
  773. File: gcc.info,  Node: Nested Functions,  Next: Constructing Calls,  Prev: Labels as Values,  Up: C Extensions
  774.  
  775. Nested Functions
  776. ================
  777.  
  778.    A "nested function" is a function defined inside another function.
  779. (Nested functions are not supported for GNU C++.)  The nested function's
  780. name is local to the block where it is defined.  For example, here we
  781. define a nested function named `square', and call it twice:
  782.  
  783.      foo (double a, double b)
  784.      {
  785.        double square (double z) { return z * z; }
  786.      
  787.        return square (a) + square (b);
  788.      }
  789.  
  790.    The nested function can access all the variables of the containing
  791. function that are visible at the point of its definition.  This is
  792. called "lexical scoping".  For example, here we show a nested function
  793. which uses an inherited variable named `offset':
  794.  
  795.      bar (int *array, int offset, int size)
  796.      {
  797.        int access (int *array, int index)
  798.          { return array[index + offset]; }
  799.        int i;
  800.        ...
  801.        for (i = 0; i < size; i++)
  802.          ... access (array, i) ...
  803.      }
  804.  
  805.    Nested function definitions are permitted within functions in the
  806. places where variable definitions are allowed; that is, in any block,
  807. before the first statement in the block.
  808.  
  809.    It is possible to call the nested function from outside the scope of
  810. its name by storing its address or passing the address to another
  811. function:
  812.  
  813.      hack (int *array, int size)
  814.      {
  815.        void store (int index, int value)
  816.          { array[index] = value; }
  817.      
  818.        intermediate (store, size);
  819.      }
  820.  
  821.    Here, the function `intermediate' receives the address of `store' as
  822. an argument.  If `intermediate' calls `store', the arguments given to
  823. `store' are used to store into `array'.  But this technique works only
  824. so long as the containing function (`hack', in this example) does not
  825. exit.
  826.  
  827.    If you try to call the nested function through its address after the
  828. containing function has exited, all hell will break loose.  If you try
  829. to call it after a containing scope level has exited, and if it refers
  830. to some of the variables that are no longer in scope, you may be lucky,
  831. but it's not wise to take the risk.  If, however, the nested function
  832. does not refer to anything that has gone out of scope, you should be
  833. safe.
  834.  
  835.    GNU CC implements taking the address of a nested function using a
  836. technique called "trampolines".   A paper describing them is available
  837. as `http://master.debian.org/~karlheg/Usenix88-lexic.pdf'.
  838.  
  839.    A nested function can jump to a label inherited from a containing
  840. function, provided the label was explicitly declared in the containing
  841. function (*note Local Labels::.).  Such a jump returns instantly to the
  842. containing function, exiting the nested function which did the `goto'
  843. and any intermediate functions as well.  Here is an example:
  844.  
  845.      bar (int *array, int offset, int size)
  846.      {
  847.        __label__ failure;
  848.        int access (int *array, int index)
  849.          {
  850.            if (index > size)
  851.              goto failure;
  852.            return array[index + offset];
  853.          }
  854.        int i;
  855.        ...
  856.        for (i = 0; i < size; i++)
  857.          ... access (array, i) ...
  858.        ...
  859.        return 0;
  860.      
  861.       /* Control comes here from `access'
  862.          if it detects an error.  */
  863.       failure:
  864.        return -1;
  865.      }
  866.  
  867.    A nested function always has internal linkage.  Declaring one with
  868. `extern' is erroneous.  If you need to declare the nested function
  869. before its definition, use `auto' (which is otherwise meaningless for
  870. function declarations).
  871.  
  872.      bar (int *array, int offset, int size)
  873.      {
  874.        __label__ failure;
  875.        auto int access (int *, int);
  876.        ...
  877.        int access (int *array, int index)
  878.          {
  879.            if (index > size)
  880.              goto failure;
  881.            return array[index + offset];
  882.          }
  883.        ...
  884.      }
  885.  
  886. 
  887. File: gcc.info,  Node: Constructing Calls,  Next: Naming Types,  Prev: Nested Functions,  Up: C Extensions
  888.  
  889. Constructing Function Calls
  890. ===========================
  891.  
  892.    Using the built-in functions described below, you can record the
  893. arguments a function received, and call another function with the same
  894. arguments, without knowing the number or types of the arguments.
  895.  
  896.    You can also record the return value of that function call, and
  897. later return that value, without knowing what data type the function
  898. tried to return (as long as your caller expects that data type).
  899.  
  900. `__builtin_apply_args ()'
  901.      This built-in function returns a pointer of type `void *' to data
  902.      describing how to perform a call with the same arguments as were
  903.      passed to the current function.
  904.  
  905.      The function saves the arg pointer register, structure value
  906.      address, and all registers that might be used to pass arguments to
  907.      a function into a block of memory allocated on the stack.  Then it
  908.      returns the address of that block.
  909.  
  910. `__builtin_apply (FUNCTION, ARGUMENTS, SIZE)'
  911.      This built-in function invokes FUNCTION (type `void (*)()') with a
  912.      copy of the parameters described by ARGUMENTS (type `void *') and
  913.      SIZE (type `int').
  914.  
  915.      The value of ARGUMENTS should be the value returned by
  916.      `__builtin_apply_args'.  The argument SIZE specifies the size of
  917.      the stack argument data, in bytes.
  918.  
  919.      This function returns a pointer of type `void *' to data describing
  920.      how to return whatever value was returned by FUNCTION.  The data
  921.      is saved in a block of memory allocated on the stack.
  922.  
  923.      It is not always simple to compute the proper value for SIZE.  The
  924.      value is used by `__builtin_apply' to compute the amount of data
  925.      that should be pushed on the stack and copied from the incoming
  926.      argument area.
  927.  
  928. `__builtin_return (RESULT)'
  929.      This built-in function returns the value described by RESULT from
  930.      the containing function.  You should specify, for RESULT, a value
  931.      returned by `__builtin_apply'.
  932.  
  933. 
  934. File: gcc.info,  Node: Naming Types,  Next: Typeof,  Prev: Constructing Calls,  Up: C Extensions
  935.  
  936. Naming an Expression's Type
  937. ===========================
  938.  
  939.    You can give a name to the type of an expression using a `typedef'
  940. declaration with an initializer.  Here is how to define NAME as a type
  941. name for the type of EXP:
  942.  
  943.      typedef NAME = EXP;
  944.  
  945.    This is useful in conjunction with the statements-within-expressions
  946. feature.  Here is how the two together can be used to define a safe
  947. "maximum" macro that operates on any arithmetic type:
  948.  
  949.      #define max(a,b) \
  950.        ({typedef _ta = (a), _tb = (b);  \
  951.          _ta _a = (a); _tb _b = (b);     \
  952.          _a > _b ? _a : _b; })
  953.  
  954.    The reason for using names that start with underscores for the local
  955. variables is to avoid conflicts with variable names that occur within
  956. the expressions that are substituted for `a' and `b'.  Eventually we
  957. hope to design a new form of declaration syntax that allows you to
  958. declare variables whose scopes start only after their initializers;
  959. this will be a more reliable way to prevent such conflicts.
  960.  
  961. 
  962. File: gcc.info,  Node: Typeof,  Next: Lvalues,  Prev: Naming Types,  Up: C Extensions
  963.  
  964. Referring to a Type with `typeof'
  965. =================================
  966.  
  967.    Another way to refer to the type of an expression is with `typeof'.
  968. The syntax of using of this keyword looks like `sizeof', but the
  969. construct acts semantically like a type name defined with `typedef'.
  970.  
  971.    There are two ways of writing the argument to `typeof': with an
  972. expression or with a type.  Here is an example with an expression:
  973.  
  974.      typeof (x[0](1))
  975.  
  976. This assumes that `x' is an array of functions; the type described is
  977. that of the values of the functions.
  978.  
  979.    Here is an example with a typename as the argument:
  980.  
  981.      typeof (int *)
  982.  
  983. Here the type described is that of pointers to `int'.
  984.  
  985.    If you are writing a header file that must work when included in
  986. ANSI C programs, write `__typeof__' instead of `typeof'.  *Note
  987. Alternate Keywords::.
  988.  
  989.    A `typeof'-construct can be used anywhere a typedef name could be
  990. used.  For example, you can use it in a declaration, in a cast, or
  991. inside of `sizeof' or `typeof'.
  992.  
  993.    * This declares `y' with the type of what `x' points to.
  994.  
  995.           typeof (*x) y;
  996.  
  997.    * This declares `y' as an array of such values.
  998.  
  999.           typeof (*x) y[4];
  1000.  
  1001.    * This declares `y' as an array of pointers to characters:
  1002.  
  1003.           typeof (typeof (char *)[4]) y;
  1004.  
  1005.      It is equivalent to the following traditional C declaration:
  1006.  
  1007.           char *y[4];
  1008.  
  1009.      To see the meaning of the declaration using `typeof', and why it
  1010.      might be a useful way to write, let's rewrite it with these macros:
  1011.  
  1012.           #define pointer(T)  typeof(T *)
  1013.           #define array(T, N) typeof(T [N])
  1014.  
  1015.      Now the declaration can be rewritten this way:
  1016.  
  1017.           array (pointer (char), 4) y;
  1018.  
  1019.      Thus, `array (pointer (char), 4)' is the type of arrays of 4
  1020.      pointers to `char'.
  1021.  
  1022. 
  1023. File: gcc.info,  Node: Lvalues,  Next: Conditionals,  Prev: Typeof,  Up: C Extensions
  1024.  
  1025. Generalized Lvalues
  1026. ===================
  1027.  
  1028.    Compound expressions, conditional expressions and casts are allowed
  1029. as lvalues provided their operands are lvalues.  This means that you
  1030. can take their addresses or store values into them.
  1031.  
  1032.    Standard C++ allows compound expressions and conditional expressions
  1033. as lvalues, and permits casts to reference type, so use of this
  1034. extension is deprecated for C++ code.
  1035.  
  1036.    For example, a compound expression can be assigned, provided the last
  1037. expression in the sequence is an lvalue.  These two expressions are
  1038. equivalent:
  1039.  
  1040.      (a, b) += 5
  1041.      a, (b += 5)
  1042.  
  1043.    Similarly, the address of the compound expression can be taken.
  1044. These two expressions are equivalent:
  1045.  
  1046.      &(a, b)
  1047.      a, &b
  1048.  
  1049.    A conditional expression is a valid lvalue if its type is not void
  1050. and the true and false branches are both valid lvalues.  For example,
  1051. these two expressions are equivalent:
  1052.  
  1053.      (a ? b : c) = 5
  1054.      (a ? b = 5 : (c = 5))
  1055.  
  1056.    A cast is a valid lvalue if its operand is an lvalue.  A simple
  1057. assignment whose left-hand side is a cast works by converting the
  1058. right-hand side first to the specified type, then to the type of the
  1059. inner left-hand side expression.  After this is stored, the value is
  1060. converted back to the specified type to become the value of the
  1061. assignment.  Thus, if `a' has type `char *', the following two
  1062. expressions are equivalent:
  1063.  
  1064.      (int)a = 5
  1065.      (int)(a = (char *)(int)5)
  1066.  
  1067.    An assignment-with-arithmetic operation such as `+=' applied to a
  1068. cast performs the arithmetic using the type resulting from the cast,
  1069. and then continues as in the previous case.  Therefore, these two
  1070. expressions are equivalent:
  1071.  
  1072.      (int)a += 5
  1073.      (int)(a = (char *)(int) ((int)a + 5))
  1074.  
  1075.    You cannot take the address of an lvalue cast, because the use of its
  1076. address would not work out coherently.  Suppose that `&(int)f' were
  1077. permitted, where `f' has type `float'.  Then the following statement
  1078. would try to store an integer bit-pattern where a floating point number
  1079. belongs:
  1080.  
  1081.      *&(int)f = 1;
  1082.  
  1083.    This is quite different from what `(int)f = 1' would do--that would
  1084. convert 1 to floating point and store it.  Rather than cause this
  1085. inconsistency, we think it is better to prohibit use of `&' on a cast.
  1086.  
  1087.    If you really do want an `int *' pointer with the address of `f',
  1088. you can simply write `(int *)&f'.
  1089.  
  1090. 
  1091. File: gcc.info,  Node: Conditionals,  Next: Long Long,  Prev: Lvalues,  Up: C Extensions
  1092.  
  1093. Conditionals with Omitted Operands
  1094. ==================================
  1095.  
  1096.    The middle operand in a conditional expression may be omitted.  Then
  1097. if the first operand is nonzero, its value is the value of the
  1098. conditional expression.
  1099.  
  1100.    Therefore, the expression
  1101.  
  1102.      x ? : y
  1103.  
  1104. has the value of `x' if that is nonzero; otherwise, the value of `y'.
  1105.  
  1106.    This example is perfectly equivalent to
  1107.  
  1108.      x ? x : y
  1109.  
  1110. In this simple case, the ability to omit the middle operand is not
  1111. especially useful.  When it becomes useful is when the first operand
  1112. does, or may (if it is a macro argument), contain a side effect.  Then
  1113. repeating the operand in the middle would perform the side effect
  1114. twice.  Omitting the middle operand uses the value already computed
  1115. without the undesirable effects of recomputing it.
  1116.  
  1117. 
  1118. File: gcc.info,  Node: Long Long,  Next: Complex,  Prev: Conditionals,  Up: C Extensions
  1119.  
  1120. Double-Word Integers
  1121. ====================
  1122.  
  1123.    GNU C supports data types for integers that are twice as long as
  1124. `int'.  Simply write `long long int' for a signed integer, or `unsigned
  1125. long long int' for an unsigned integer.  To make an integer constant of
  1126. type `long long int', add the suffix `LL' to the integer.  To make an
  1127. integer constant of type `unsigned long long int', add the suffix `ULL'
  1128. to the integer.
  1129.  
  1130.    You can use these types in arithmetic like any other integer types.
  1131. Addition, subtraction, and bitwise boolean operations on these types
  1132. are open-coded on all types of machines.  Multiplication is open-coded
  1133. if the machine supports fullword-to-doubleword a widening multiply
  1134. instruction.  Division and shifts are open-coded only on machines that
  1135. provide special support.  The operations that are not open-coded use
  1136. special library routines that come with GNU CC.
  1137.  
  1138.    There may be pitfalls when you use `long long' types for function
  1139. arguments, unless you declare function prototypes.  If a function
  1140. expects type `int' for its argument, and you pass a value of type `long
  1141. long int', confusion will result because the caller and the subroutine
  1142. will disagree about the number of bytes for the argument.  Likewise, if
  1143. the function expects `long long int' and you pass `int'.  The best way
  1144. to avoid such problems is to use prototypes.
  1145.  
  1146. 
  1147. File: gcc.info,  Node: Complex,  Next: Hex Floats,  Prev: Long Long,  Up: C Extensions
  1148.  
  1149. Complex Numbers
  1150. ===============
  1151.  
  1152.    GNU C supports complex data types.  You can declare both complex
  1153. integer types and complex floating types, using the keyword
  1154. `__complex__'.
  1155.  
  1156.    For example, `__complex__ double x;' declares `x' as a variable
  1157. whose real part and imaginary part are both of type `double'.
  1158. `__complex__ short int y;' declares `y' to have real and imaginary
  1159. parts of type `short int'; this is not likely to be useful, but it
  1160. shows that the set of complex types is complete.
  1161.  
  1162.    To write a constant with a complex data type, use the suffix `i' or
  1163. `j' (either one; they are equivalent).  For example, `2.5fi' has type
  1164. `__complex__ float' and `3i' has type `__complex__ int'.  Such a
  1165. constant always has a pure imaginary value, but you can form any
  1166. complex value you like by adding one to a real constant.
  1167.  
  1168.    To extract the real part of a complex-valued expression EXP, write
  1169. `__real__ EXP'.  Likewise, use `__imag__' to extract the imaginary part.
  1170.  
  1171.    The operator `~' performs complex conjugation when used on a value
  1172. with a complex type.
  1173.  
  1174.    GNU CC can allocate complex automatic variables in a noncontiguous
  1175. fashion; it's even possible for the real part to be in a register while
  1176. the imaginary part is on the stack (or vice-versa).  None of the
  1177. supported debugging info formats has a way to represent noncontiguous
  1178. allocation like this, so GNU CC describes a noncontiguous complex
  1179. variable as if it were two separate variables of noncomplex type.  If
  1180. the variable's actual name is `foo', the two fictitious variables are
  1181. named `foo$real' and `foo$imag'.  You can examine and set these two
  1182. fictitious variables with your debugger.
  1183.  
  1184.    A future version of GDB will know how to recognize such pairs and
  1185. treat them as a single variable with a complex type.
  1186.  
  1187. 
  1188. File: gcc.info,  Node: Hex Floats,  Next: Zero Length,  Prev: Complex,  Up: C Extensions
  1189.  
  1190. Hex Floats
  1191. ==========
  1192.  
  1193.    GNU CC recognizes floating-point numbers written not only in the
  1194. usual decimal notation, such as `1.55e1', but also numbers such as
  1195. `0x1.fp3' written in hexadecimal format.  In that format the `0x' hex
  1196. introducer and the `p' or `P' exponent field are mandatory.  The
  1197. exponent is a decimal number that indicates the power of 2 by which the
  1198. significand part will be multiplied.  Thus `0x1.f' is 1 15/16, `p3'
  1199. multiplies it by 8, and the value of `0x1.fp3' is the same as `1.55e1'.
  1200.  
  1201.    Unlike for floating-point numbers in the decimal notation the
  1202. exponent is always required in the hexadecimal notation.  Otherwise the
  1203. compiler would not be able to resolve the ambiguity of, e.g., `0x1.f'.
  1204. This could mean `1.0f' or `1.9375' since `f' is also the extension for
  1205. floating-point constants of type `float'.
  1206.  
  1207. 
  1208. File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Hex Floats,  Up: C Extensions
  1209.  
  1210. Arrays of Length Zero
  1211. =====================
  1212.  
  1213.    Zero-length arrays are allowed in GNU C.  They are very useful as
  1214. the last element of a structure which is really a header for a
  1215. variable-length object:
  1216.  
  1217.      struct line {
  1218.        int length;
  1219.        char contents[0];
  1220.      };
  1221.      
  1222.      {
  1223.        struct line *thisline = (struct line *)
  1224.          malloc (sizeof (struct line) + this_length);
  1225.        thisline->length = this_length;
  1226.      }
  1227.  
  1228.    In standard C, you would have to give `contents' a length of 1, which
  1229. means either you waste space or complicate the argument to `malloc'.
  1230.  
  1231.